package poi;

import com.databricks.spark.csv.CsvParser;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.sql.DataFrame;
import org.apache.spark.sql.SQLContext;

/**
 * <pre>
 * Created with IntelliJ IDEA.
 * User: zhengzhi
 * Date: 2017/7/18
 * To change this template use File | Settings | File Templates.
 * </pre>
 */
public class SparkReadCsv {
    public static void main(String[] args) {
        SparkConf conf = new SparkConf().setAppName("CSVParse").setMaster("local[2]");
        JavaSparkContext sc = new JavaSparkContext(conf);
//        JavaRDD<String> data = sc.textFile("E:/HqData/客流来源按天统计.csv");
        SQLContext sqlContext = new SQLContext(sc);

        DataFrame dataFrame = (new CsvParser()).withUseHeader(true).csvFile(sqlContext, "E:/HqData/客流来源按天统计.csv");
        dataFrame.registerTempTable("flow");

        sqlContext.sql("Select 游客数 from flow").show();


    }
}
